using System.Web;
using System.Web.Http;
using SmartLink.DTOS.Account;
using SmartLink.Application.IServices;
using SmartLink.DTOS;
using SmartLink.DTOS.Permission;
using SmartLink.Infrastructure;
using SmartLink.WebApi.Filter;
using SmartLink.DTOS.Base;
using SmartLink.DTOS.SysBasic;
using System.Collections.Generic;

namespace SmartLink.WebApi.Controllers
{
    public class AccountController : BaseAPIControl
    {
        private IAccountAppServices _accountServices;

        public AccountController(IAccountAppServices accountServices)
        {
            _accountServices = accountServices;
        }

        /// <summary>
        /// 登录
        /// </summary>
        [AllowAnonymous]
        [HttpPost]
        public Results<LoginResponseDTO> Login([FromBody]LoginDTO model)
        {
            if (string.IsNullOrEmpty(model.Ip))
            {
                model.Ip = HttpContext.Current.Request.UserHostAddress;
            }
            return _accountServices.Login(model);
        }
        /// <summary>
        /// 退出登录
        /// </summary>
        [HttpGet]
        public Results<bool> Logout()
        {
            Results<bool> results = new Results<bool>();
            if (CurUserInfo == null)
            {
                results.Data = true;
                return results;
            }
            int userId = CurUserInfo.UserId;
            return _accountServices.Logout(userId);
        }




        //#region 用户管理

        ///// <summary>
        ///// 获取用户分页列表
        ///// </summary>
        ///// <param name="pagePara"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results<PageData<UserListItemDTO>> GetUserList([FromBody]UserPagePara pagePara)
        //{
        //    return _accountServices.GetUserList(pagePara, CurUserInfo.UserId);
        //}
        ///// <summary>
        ///// 获取用户信息
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results<UserInfoDTO> GetUserInfo([FromBody]IDDTO model)
        //{
        //    return _accountServices.GetUserInfo(model.ID);
        //}
        ///// <summary>
        ///// 添加用户
        ///// </summary>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results AddUser([FromBody]AddUserDTO user)
        //{
        //    return _accountServices.AddUser(user);
        //}
        ///// <summary>
        ///// 修改用户信息
        ///// </summary>
        ///// <param name="user"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results UpdateUserBasicInfo([FromBody]UserBasicInfoUpdateDTO user)
        //{
        //    return _accountServices.UpdateUserBasicInfo(user);
        //}
        ///// <summary>
        ///// 删除用户
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results DeleteUser([FromBody]IDDTO model)
        //{
        //    return _accountServices.DeleteUser(model.ID);
        //}
        ///// <summary>
        ///// 首次登陆强制更新密码
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[FirstLoginCheck(false)]
        //[HttpPost]
        //public Results ForceUpdatePassword([FromBody]ForceUpdatePasswordDTO model)
        //{
        //    return _accountServices.ForceUpdatePassword(model.Password);
        //}
        ///// <summary>
        ///// 更新用户账号状态
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results UpdateUserStatus([FromBody]UpdateUserStatusDTO model)
        //{
        //    return _accountServices.UpdateUserStatus(model);
        //}
        ///// <summary>
        ///// 重置密码
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //public Results ResetPassword(IDDTO model)
        //{
        //    return _accountServices.ResetPassword(model.ID);
        //}

        ///// <summary>
        ///// 根据组织ID，获取组织用户列表
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //public Results<IEnumerable<UserSelectListItemDTO>> GetUserSelectList(InOIDODIDDTO model)
        //{
        //    return _accountServices.GetUserSelectList(model.ID, model.IsDept);
        //}

        ///// <summary>
        ///// 获取用户的所有权限数据
        ///// </summary>
        ///// <param name="userIdDTO"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[NonAction]
        //public Results<UserRightsDto> GetUserAllRights([FromBody] UserIDDTO userIdDTO)
        //{
        //    return _accountServices.GetUserAllRights(userIdDTO.UserId);
        //}

        ///// <summary>
        ///// 账户修改自身密码
        ///// </summary>
        ///// <param name="modifyPwdDTO"></param>
        ///// <returns></returns>
        //[HttpPost]
        //public Results ModifyPassword([FromBody]PwdModifyDTO modifyPwdDTO)
        //{
        //    return _accountServices.ModifyPassword(modifyPwdDTO, CurUserId);
        //}

        //#endregion

    
    }
}
